package excercise;

import java.util.Scanner;

public class EX05_032 {

	public static void main(String[] args) {
		
		JuminVO jv = new JuminVO();
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			System.out.print("확인하실 주민번호를 입력하시오 : ");
			jv.setJuminNo(sc.next());
			if (jv.getJuminNo().length() != 13) {
				System.out.println("숫자 13자리를 다시 확인하시고 입력하세요");
			} else { break; }
		}
		jv.setResult(JuminService.JuminResult(jv.getJuminNo()));
		
		System.out.println(jv.toString());

	}
}

class JuminVO {
	private String juminNo;
	private String result;
	
	public JuminVO() {
		juminNo = null;
		result = null;
	}
	public JuminVO(String juminNo) { this.juminNo = juminNo; }
	
	public void setJuminNo(String juminNo) { this.juminNo = juminNo; }
	public void setResult(String result) { this.result = result; }
	public String getJuminNo() { return juminNo; }
	public String getResult() { return result; }
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("○ 입력하신 주민등록 번호 : ").append(getJuminNo().substring(0, 6))
				.append(" - ").append(getJuminNo().substring(6,13))
				.append("\n○ 주민번호 확인 결과 : ").append(getResult());
		return sb.toString();
	}
}

class JuminService {
		
	static String JuminResult(String JuminNo) {
		String result = null;
		int a;
		a = (Integer.parseInt(JuminNo.substring(0, 1)) * 2) + (Integer.parseInt(JuminNo.substring(1, 2)) * 3)
				+ (Integer.parseInt(JuminNo.substring(2, 3)) * 4) + (Integer.parseInt(JuminNo.substring(3, 4)) * 5)
				+ (Integer.parseInt(JuminNo.substring(4, 5)) * 6) + (Integer.parseInt(JuminNo.substring(5, 6)) * 7)
				+ (Integer.parseInt(JuminNo.substring(6, 7)) * 8) + (Integer.parseInt(JuminNo.substring(7, 8)) * 9)
				+ (Integer.parseInt(JuminNo.substring(8, 9)) * 2) + (Integer.parseInt(JuminNo.substring(9, 10)) * 3)
				+ (Integer.parseInt(JuminNo.substring(10, 11)) * 4) + (Integer.parseInt(JuminNo.substring(11, 12)) * 5);
		
		if  (11 - (a % 11) == Integer.parseInt(JuminNo.substring(12, 13))) {
			result =  "유효한 주민번호입니다.";
			return result;
		} else { result = "유효하지 않은 주민번호입니다."; return result;}
	}
}
